package snippet;

public class T700 {
	@SuppressWarnings("unused")
	public static void main(String[] args) {
		TreeNode t4 = new TreeNode(2);
		TreeNode t2 = new TreeNode(2);
		TreeNode t7 = new TreeNode(2);
		TreeNode t1 = new TreeNode(5);
		TreeNode t3 = new TreeNode(2);
		t4.left = t2;
		t4.right = t7;
		t2.left = t1;
		t2.right = t3;
		boolean t = new T700().isUnivalTree(t4);
		System.out.println(t);

	}
	
	 public boolean isUnivalTree(TreeNode root) {
		 boolean b1=true,b2=true;
		 if(root.left!=null) {
			 b1=(root.val==root.left.val)&&isUnivalTree(root.left);
		 }
		 if(root.right!=null) {
			 b2=(root.val==root.right.val)&&isUnivalTree(root.right);
		 }
		return b1&&b2;
	        
	    }
	
	 
	public TreeNode searchBST(TreeNode root, int val) {
		if (root == null)
			return null;
		if (root.val == val) {
			return root;
		} else if (root.val < val) {
			return searchBST(root.right, val);
		} else {
			return searchBST(root.left, val);
		}

	}
}
